<?php

/**
 * Subclass for representing a row from the 'tutor' table.
 *
 * 
 *
 * @package lib.model
 */ 
class Tutor extends BaseTutor
{
  public function getName()
  {
    return $this->getFirstname() . ' ' . $this->getLastname();
  }

  public function getSubjects()
  {
    $c = new Criteria();
    $subjects = array();
     foreach($this->getSubjectTutorsJoinSubject($c) as $ref) {
        $subjects[] = $ref->getSubject();
     }
     return $subjects;
  }

  public function getAvailabilities()
  {
    $c = new Criteria();
    $availabilities = array();
    foreach($this->getAvailabilityTutorsJoinAvailability($c) as $ref) {
       $availabilities[] = $ref->getAvailability();
    }
    return $availabilities;
  }

  public function setAvailabilities($availabilities, $tutorid)
  {
    $c = new Criteria();
    $c->add(AvailabilityTutorPeer::TUTOR_ID, $tutorid);
    AvailabilityTutorPeer::doDelete($c);
    foreach ($availabilities as $availability)
    {
      $avail = new AvailabilityTutor();
      $avail->setAvailabilityId($availability);
      $avail->setTutorId($tutorid);
      $avail->save();
    }
  }

  public function setSubjects($subjects, $tutorid)
  {
    $c = new Criteria();
    $c->add(SubjectTutorPeer::TUTOR_ID, $tutorid);
    SubjectTutorPeer::doDelete($c);
    foreach ($subjects as $subject)
    {
      $subj = new SubjectTutor();
      $subj->setSubjectId($subject);
      $subj->setTutorId($tutorid);
      $subj->save();
    }
  }
}
